/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


bool isPalindrome(struct ListNode* head)
{
    struct ListNode* fast=head,*slow=head;
    struct ListNode* p1,*p2,*p3;
    while(fast&&fast->next)
    {
        fast=fast->next->next;
        slow=slow->next;
    }
    p1=NULL,p2=slow,p3=p2->next;
    while(p2)
    {
        p2->next=p1;
        p1=p2;
        p2=p3;
        if(p3)
        {
            p3=p3->next;
        }
    }
    while(p1)
    {
        if(p1->val!=head->val)
        {
            return false;
        }
        head=head->next;
        p1=p1->next;
    }
    return true;
}